﻿using Framework.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Framework.Common.Html;

namespace Framework.UnitTest
{


    /// <summary>
    ///这是 HttpWebHelperTest 的测试类，旨在
    ///包含所有 HttpWebHelperTest 单元测试
    ///</summary>
    [TestClass()]
    public class HttpWebHelperTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///GetHtml 的测试
        ///</summary>
        [TestMethod()]
        public void GetHtmlTest()
        {
            string strUri = "http://login.tool.hexun.com/OtherInterFace/IFR_userLoginDialog_01.aspx?hexunMember_loginSetup_referrer=http://kd.hexun.com/";
            bool actual;
            RequestParameter
                p = new RequestParameter
                {
                    Url = strUri,
                    InitCookie = true,
                    ContentType = "multipart/form-data",
                    PostData = HttpWebHelper.CreatePostData("username=beilin261&password=1qaz2wsx&LoginStateAuto_source=checkbox&Submit=%B5%C7%C2%BC&LoginStateAuto=1&action=sub&hexunMember_loginSetup_referrer=http%3A%2F%2Fnews.hexun.com%2F")
                };
            actual = HttpWebHelper.GetHtml(p);
            p.Url = "http://kd.hexun.com/admin/news";
            p.InitCookie = false;
            actual = HttpWebHelper.GetHtml(p);
            Assert.AreEqual(actual, true);

        }
        [TestMethod()]
        public void Login()
        {
            string strUri = "http://mis.hexun.com/checkuser.html";
            bool actual;
            Framework.Common.RequestParameter
                p = new RequestParameter
                {
                    Url = strUri,
                    InitCookie = true,
                    ContentType = "application/x-www-form-urlencoded",
                    PostData = HttpWebHelper.CreatePostData("UserName=886703&UserPassword=8888&x=27&y=9"),
                    UserAgent = "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.3)"
                };
            actual = HttpWebHelper.GetHtml(p);
            p.Url = "http://mis.hexun.com/studiocast/Benq.aspx?do=cp";
            p.Method = "GET";
            p.PostData = null;
            p.InitCookie = false;
            actual = HttpWebHelper.GetHtml(p);
            Assert.AreEqual(actual, true);
        }

        [TestMethod]
        public void HtmlAgilityPack()
        {
            string strUri = "http://kd.hexun.com";
            bool actual;
            RequestParameter
                p = new RequestParameter
                {
                    Url = strUri,
                    InitCookie = true,
                    ContentType = "application/x-www-form-urlencoded",
                    UserAgent = "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.3)"
                };
            actual = HttpWebHelper.GetHtml(p);
        }
    }
}
